package com.team.RunsFast_Api.controller;

import com.team.RunsFast_Api.config.SystemConfig;
import com.team.RunsFast_Api.dto.CouponInfoDto;
import com.team.RunsFast_Api.service.intf.CouponInfoService;
import com.team.runsfast.entity.CouponInfo;
import com.team.runsfast.vo.R;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/couponInfo/")
@Api(tags = "优惠券操作")
@CrossOrigin
public class CouponInfoController {

    @Autowired
    private CouponInfoService couponInfoService;

    @GetMapping("save")
    public R save(@RequestBody  CouponInfo couponInfo){
        return couponInfoService.save(couponInfo);
    }

    @GetMapping("queryAll")
    public R queryAll(){
        return couponInfoService.queryAll();
    }

    @GetMapping("selectByUid")
    public R selectByUid(String token){
        return R.ok(couponInfoService.selectByUid(token));
    }

    @GetMapping("discountPrice")
    public R discountPrice(CouponInfoDto dto, HttpServletRequest request){
        return couponInfoService.discountPrice(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @GetMapping("updateCoupon")
    public R updateCoupon(long id){
        return couponInfoService.updateCoupon(id);
    }
}
